package com.lh.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author LuoHang
 * @Date 2022-05-10 19:19
 **/
public class MyLog {
    private static final Map<String, Logger> LOGS = new HashMap<>(32);

    private MyLog(){}

    private static Logger getLogger(Class<?> cls){
        Logger logger = LOGS.get(cls.getName());
        if (logger == null){
            logger = LoggerFactory.getLogger(cls);
            LOGS.put(cls.getName(), logger);
        }
        return logger;
    }

    public static void info(Class<?> cls, String msg){
        Logger logger = getLogger(cls);
        logger.info(msg);
    }

    public static void debug(Class<?> cls, String msg){
        Logger logger = getLogger(cls);
        logger.debug(msg);
    }

    public static void warn(Class<?> cls, String msg){
        Logger logger = getLogger(cls);
        logger.warn(msg);
    }

    public static void error(Class<?> cls, String msg){
        Logger logger = getLogger(cls);
        logger.error(msg);
    }

    public static void trace(Class<?> cls, String msg){
        Logger logger = getLogger(cls);
        logger.trace(msg);
    }
}
